// (c) 2008 Kickstone Technology Ltd

#pragma once

class CCriticalSection : CRITICAL_SECTION {
public:
	CCriticalSection(){
		::InitializeCriticalSection(this);
	}

	~CCriticalSection(){
		::DeleteCriticalSection(this);
	}
	
	void lock(){
		EnterCriticalSection(this);
	}

	void unlock(){
		LeaveCriticalSection(this);
	}

};

class CLocalLock {
public:
	CLocalLock(CCriticalSection &cs) : m_cs(&cs){
		m_cs->lock();
	}

	~CLocalLock(){
		m_cs->unlock();
	}

private:
	CCriticalSection *m_cs;
};
